--- import PageLayout from "@/layouts/Base.astro"; import Weather from "@/components/now/Weather.astro"; import { POSTS_API } from "@/data/constants"; import { createMarkdownRenderer } from "@/utils"; export const prerender = false; const md = await createMarkdownRenderer(); const { slug } = Astro.params; if (!slug) { return Astro.redirect("/now"); } interface PostDetail { short_id: string; title: string | null; slug: string; alias: string | null; canonical_url: string | null; published_date: string | null; meta_description: string | null; meta_image: string | null; lang: string; tags: string | null; content: string; created_at: string; updated_at: string; weather: string | null; } let title: string | null = "Post"; let description = "A post"; let contentHTML = ""; let publishedAt = ""; let errorMessage = ""; let weatherRaw = ""; let isError = false; try { const res = await fetch(`${POSTS_API}/posts/${encodeURIComponent(slug)}`); if (res.status === 404) { Astro.response.status = 404; isError = true; title = "Not Found"; errorMessage = "The post you're looking for doesn't exist."; } else if (!res.ok) { throw new Error(`HTTP ${res.status}`); } else { const post = (await res.json()) as PostDetail; title = post.title; description = post.meta_description || (post.content ? post.content.slice(0, 160) : description); publishedAt = post.published_date ? new Date(post.published_date).toLocaleDateString() : ""; contentHTML = md.render(post.content || ""); weatherRaw = post.weather || ""; } } catch (err) { console.error("Error fetching post:", err); Astro.response.status = 500; isError = true; title = "Error"; errorMessage = "Something went wrong while loading this post."; } const meta = { title: title || "Post", description, }; ---
{isError ? ( <>

{title}

{errorMessage}

← Back to Now ) : ( <> {title &&

{title}

}
{weatherRaw && }
)}